/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class DateFormat {

    /**
     * Convert String to Sql Date
     *
     * @param sdate
     * @param pattern
     * @return java.sql.Date
     */
    public static Date toDate(String sdate, String pattern) {
        try {
            SimpleDateFormat fm = new SimpleDateFormat(pattern);
            java.util.Date time = fm.parse(sdate);
            return new Date(time.getTime());
        } catch (ParseException ex) {
            Logger.getLogger(DateFormat.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public static String toString(Date date, String pattern) {
        return new SimpleDateFormat(pattern).format(date);
    }
    public static java.sql.Date toSqlDate(java.util.Date date) {
        return new java.sql.Date(date.getTime());
    }
    public static java.util.Date toJavaDate(java.sql.Date date) {
        return new java.util.Date(date.getTime());
    }
    public static void main(String[] args) {
    }
}
